//
//  RealNameViewController.m
//  MagicZhao
//
//  Created by hy002 on 2017/12/8.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "RealNameViewController.h"
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import "SecurityDepositViewController.h"

static NSString *cellPath = @"RealNameCell";
@interface RealNameViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate>
{
    UIImageView *frontFaceView;
    UIImageView *reverseSideView;
    UIImageView *frontFaceBView;
    UIImageView *reverseSideBView;
    NSString *agreementStr;
    UIButton *agreement;
    BOOL isSelect;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSArray *titAry;
@property (nonatomic, strong)NSMutableArray *imgAry;
@property (nonatomic, strong)NSString *nameStr;
@property (nonatomic, strong)NSString *carNumStr;
@property (nonatomic, strong)NSString *frontImgUrl;
@property (nonatomic, strong)NSString *reveImgUrl;
@property (nonatomic, assign)NSInteger closeImgType;

@property (nonatomic, strong) UIView *coverView;
@property (nonatomic, strong) UIView *tipView;
@end

@implementation RealNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    isSelect = YES;
    [self requestRegistAgreement];
    _nameStr = @"";
    _carNumStr = @"";
    _frontImgUrl = @"";
    _reveImgUrl = @"";
    _closeImgType = 0;
    _imgAry = [NSMutableArray arrayWithCapacity:0];
    _titAry = @[@"真实姓名",@"身份证号"];
    [self creatUI];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = BacksColor;
    self.navigationItem.title = @"实名认证";
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-SCREER_HeiX-STA_NAV_HEIGHT) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_tableview];
    
}

//协议
- (void)agreementAction
{
    [self showTipView];
}

- (void)showTipView {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tipViewKeyboardHide:)];
    singleTap.cancelsTouchesInView = NO;
    [window addGestureRecognizer:singleTap];
    if (!_coverView) {
        _coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _coverView.backgroundColor = [UIColor blackColor];
        _coverView.alpha = 0;
        [window addSubview:_coverView];
    }
    _coverView.hidden = NO;
    
    if (!_tipView) {
        _tipView = [[UIView alloc] initWithFrame:CGRectMake(40, (SCREEN_HEIGHT - 400*displaywidth)/2, SCREEN_WIDTH - 80, 400*displaywidth)];
        _tipView.backgroundColor = [UIColor whiteColor];
        _tipView.alpha = 0;
        _tipView.layer.cornerRadius = 2;
        _tipView.layer.masksToBounds = YES;
        [window addSubview:_tipView];
    }
    _tipView.hidden = NO;
    [UIView transitionWithView:_coverView duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        _coverView.alpha = 0.4;
        _tipView.alpha = 1;
    } completion:nil];
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 16, _tipView.frame.size.width, 30)];
    tipLabel.text = @"《身份认证协议》";
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.font = [UIFont systemFontOfSize:18];
    tipLabel.textColor = UIColorHexValue(0x4D4D4D);
    [_tipView addSubview:tipLabel];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(18, 56, _tipView.frame.size.width - 36, 250*displaywidth)];
    [webView loadHTMLString:agreementStr baseURL:nil];
    webView.backgroundColor = [UIColor whiteColor];
    [_tipView addSubview:webView];
    
    UILabel *lineLabel = [ZCControl createLabelWithFrame:CGRectMake(0, _tipView.frame.size.height - 50, _tipView.frame.size.width, 1) Font:16 Text:nil Color:nil];
    lineLabel.backgroundColor = RGB(233, 234, 233);
    [_tipView addSubview:lineLabel];
    
    UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(25, _tipView.frame.size.height - 40, (_tipView.frame.size.width - 100) / 2, 30)];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [cancelBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
    cancelBtn.layer.cornerRadius = 5;
    cancelBtn.layer.masksToBounds = YES;
    cancelBtn.layer.borderColor = ThemeColor.CGColor;
    cancelBtn.layer.borderWidth = 1;
    cancelBtn.backgroundColor = [UIColor whiteColor];
    [cancelBtn setTitle:@"不同意" forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(onClickCancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [_tipView addSubview:cancelBtn];
    UIButton *ensureBtn = [[UIButton alloc] initWithFrame:CGRectMake(25*3 + (_tipView.frame.size.width - 100) / 2, _tipView.frame.size.height - 40, (_tipView.frame.size.width - 100) / 2, 30)];
    ensureBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    ensureBtn.backgroundColor = ThemeColor;
    ensureBtn.layer.cornerRadius = 5;
    ensureBtn.layer.masksToBounds = YES;
    [ensureBtn setTitle:@"同意" forState:UIControlStateNormal];
    [ensureBtn addTarget:self action:@selector(onClickEnsureBtn) forControlEvents:UIControlEventTouchUpInside];
    [_tipView addSubview:ensureBtn];
}

- (void)onClickCancelBtn {
    isSelect = NO;
    [agreement setImage:[UIImage imageNamed:@"xuankuang(3)"] forState:UIControlStateNormal];
    [self hideTipView];
}

- (void)onClickEnsureBtn {
    isSelect = YES;
    [agreement setImage:[UIImage imageNamed:@"gouxuandaik"] forState:UIControlStateNormal];
    [self hideTipView];
}

-(void)tipViewKeyboardHide:(UITapGestureRecognizer*)tap {
    [self hideTipView];
}

- (void)hideTipView {
    if (_coverView) {
        [UIView transitionWithView:_coverView duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
            _coverView.alpha = 0;
        } completion:nil];
        _coverView.hidden = YES;
    }
    if (_tipView) {
        [UIView transitionWithView:_tipView duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
            _tipView.alpha = 0;
        } completion:nil];
        _tipView.hidden = YES;
    }
}

- (void)requestRegistAgreement {
    WEAKSELF;
    //    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HYBaseHandler requestGetRegistAgreeMentParmers:@{@"key":@"worker_identity_agreement"} Success:^(id obj)
     {
         //         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([obj server_Getcodecheck])
         {
             NSLog(@"%@", obj);
             agreementStr = obj[@"data"][@"propertyValue"];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         //         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 2;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.section == 0)
    {
        UILabel *namelab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, 120*displaywidth, 40*displaywidth) Font:14.0 Text:_titAry[indexPath.row] Color:RGB(77, 77, 77)];
        [cell.contentView addSubview:namelab];
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth, 49*displaywidth, SCREEN_WIDTH-15*displaywidth, 1*displaywidth)];
        lineview.backgroundColor = LinesColor;
        [cell.contentView addSubview:lineview];
        
        NSArray *pladerAry = @[@"请输入姓名",@"请输入身份证号码"];
        NSArray *textAry = @[_nameStr,_carNumStr];
        UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(100*displaywidth, 5*displaywidth, SCREEN_WIDTH-120*displaywidth, 35*displaywidth) placeholder:pladerAry[indexPath.row] passWord:NO leftImageView:nil rightImageView:nil Font:13.0];
        [textfield setValue:RGB(179, 179, 179) forKeyPath:@"_placeholderLabel.textColor"];
        textfield.textColor = RGB(77, 77, 77);
        textfield.text = textAry[indexPath.row];
        textfield.textAlignment = NSTextAlignmentRight;
        textfield.delegate = self;
        textfield.tag = 100+indexPath.row;
        [cell.contentView addSubview:textfield];
        
        
    }
    else
    {
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, 120*displaywidth, 40*displaywidth) Font:14.0 Text:@"证件照片" Color:RGB(77, 77, 77)];
        [cell.contentView addSubview:titlab];
     
        UIImageView *addView = [[UIImageView alloc] initWithFrame:CGRectMake(60*displaywidth, 50*displaywidth, SCREEN_WIDTH-120*displaywidth, 110*displaywidth)];
        if (![_frontImgUrl isEqualToString:@""])
        {
            [addView sd_setImageWithURL:[NSURL URLWithString:_frontImgUrl]];
        }
        addView.backgroundColor = [UIColor whiteColor];
        addView.contentMode = UIViewContentModeScaleAspectFit;
        addView.layer.cornerRadius = 10;
        addView.layer.masksToBounds = YES;
        addView.layer.borderColor = RGB(204, 204, 204).CGColor;
        addView.layer.borderWidth = 1;
        [cell.contentView addSubview:addView];
        frontFaceView = addView;
        CGFloat W = SCREEN_WIDTH-120*displaywidth;
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(60*displaywidth, 50*displaywidth, SCREEN_WIDTH-120*displaywidth, 110*displaywidth) ImageName:@"zm"];
        imgView.contentMode = UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:imgView];
        frontFaceBView = imgView;
        UILabel *tostLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 60*displaywidth, W-40*displaywidth, 30*displaywidth) Font:14.0 Text:@"身份证正面照片" Color:RGB(179, 179, 179)];
        tostLab.textAlignment = NSTextAlignmentCenter;
        [addView addSubview:tostLab];
        UIButton *frontBtn = [ZCControl createButtonWithFrame:CGRectMake(60*displaywidth, 50*displaywidth, SCREEN_WIDTH-120*displaywidth, 110*displaywidth) ImageName:@"" Target:self Action:@selector(frontAction) Title:nil Font:12.0];
        frontBtn.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:frontBtn];
        
        UIImageView *addBView = [[UIImageView alloc] initWithFrame:CGRectMake(60*displaywidth, 180*displaywidth, SCREEN_WIDTH-120*displaywidth, 110*displaywidth)];
        addBView.backgroundColor = [UIColor whiteColor];
        addBView.layer.cornerRadius = 10;
        addBView.layer.masksToBounds = YES;
        addBView.contentMode = UIViewContentModeScaleAspectFit;
        addBView.layer.borderColor = RGB(204, 204, 204).CGColor;
        addBView.layer.borderWidth = 1;
        [cell.contentView addSubview:addBView];
        reverseSideView = addBView;
        UIImageView *imgBView = [ZCControl createImageViewWithFrame:CGRectMake(60*displaywidth, 180*displaywidth, SCREEN_WIDTH-120*displaywidth, 110*displaywidth) ImageName:@"fanm"];
        imgBView.contentMode = UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:imgBView];
        reverseSideBView = imgBView;
        if (![_reveImgUrl isEqualToString:@""])
        {
            imgBView.image = [UIImage imageNamed:@""];
        }
        UILabel *tostBLab = [ZCControl createLabelWithFrame:CGRectMake(20*displaywidth, 60*displaywidth, W-40*displaywidth, 30*displaywidth) Font:14.0 Text:@"身份证反面照片" Color:RGB(179, 179, 179)];
        tostBLab.textAlignment = NSTextAlignmentCenter;
        [addBView addSubview:tostBLab];
        UIButton *reverseBtn = [ZCControl createButtonWithFrame:CGRectMake(60*displaywidth, 180*displaywidth, SCREEN_WIDTH-120*displaywidth, 110*displaywidth) ImageName:@"" Target:self Action:@selector(reverseAction) Title:nil Font:12.0];
        reverseBtn.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:reverseBtn];
        
        agreement = [ZCControl createButtonWithFrame:CGRectMake(30*displaywidth, CGRectGetMaxY(reverseBtn.frame) + 20*displaywidth, SCREEN_WIDTH-60*displaywidth, 20*displaywidth) ImageName:@"gouxuandaik" Target:self Action:@selector(agreementAction) Title:@"《身份认证协议》" Font:12.0];
        [agreement setTitleColor:RGB(255, 111, 25) forState:UIControlStateNormal];
        [cell.contentView addSubview:agreement];
        
        UIButton *submitBtn = [ZCControl createButtonWithFrame:CGRectMake(60*displaywidth , 340*displaywidth, SCREEN_WIDTH-120*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(submitAction) Title:@"提交" Font:15.0];
        [submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        submitBtn.backgroundColor = ThemeColor;
        [submitBtn.layer setMasksToBounds:YES];
        [submitBtn.layer setCornerRadius:5*displaywidth];
        [cell.contentView addSubview:submitBtn];
    }
    return cell;
    
}

//正面
- (void)frontAction
{
    _closeImgType = 0;
    [self.view endEditing:YES];
    [self openThePhoto];
}
//反面
- (void)reverseAction
{
    _closeImgType = 1;
    [self.view endEditing:YES];
    [self openThePhoto];
}

- (void)openThePhoto
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"选择图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    //拍照
    [alertVC addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        HYLog(@"拍照");
        [self takePhoto];
        
    }]];
    
    //从相册中选取
    [alertVC addAction:[UIAlertAction actionWithTitle:@"从相册中选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        HYLog(@"从相册中选取");
        [self choseImageWithTypeCameraTypePhotoLibrary:UIImagePickerControllerSourceTypePhotoLibrary];
        
    }]];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        HYLog(@"取消");
        [self dismissViewControllerAnimated:NO completion:nil];
    }]];
    
    [self presentViewController:alertVC animated:YES completion:nil];
}

-(void)takePhoto
{
    //    判断是否打开相机权限
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您尚未开启相机权限，请去系统设置界面打开相机权限！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
                [[UIApplication sharedApplication]openURL:url];
            }
        }];
        [alertVC addAction:okAction];
        [self presentViewController:alertVC animated:YES completion:nil];
        
        
    }
    else
    {
        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
        if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            //            设置拍照后的图片可被编辑
            picker.allowsEditing = YES;
            picker.sourceType = sourceType;
            
            [self presentViewController:picker animated:YES completion:nil];
        }else
        {
            
        }
        
    }
}

-(void)choseImageWithTypeCameraTypePhotoLibrary:(UIImagePickerControllerSourceType)type{
    
    UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = type;
    imagePicker.allowsEditing = YES;
    imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:imagePicker animated:YES completion:^{
        
    }];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    //    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"]) {
        UIImageOrientation imageOrientation = image.imageOrientation;
        if(imageOrientation!=UIImageOrientationUp)
        {
            UIGraphicsBeginImageContext(image.size);
            [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
            image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
        }
        
    }
    if (_closeImgType == 0)
    {
        frontFaceView.image = image;
        frontFaceBView.image = [UIImage imageNamed:@""];
    }
    else
    {
        reverseSideView.image = image;
        reverseSideBView.image = [UIImage imageNamed:@""];
    }
    WEAKSELF;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HttpTool uploadImageWithPath:SERVER_fileUpload params:nil thumbName:@"file" image:image success:^(id json)
     {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         if ([json server_Getcodecheck])
         {
             NSArray *urlAry = json[@"data"];
             if (urlAry.count > 0)
             {
                 NSString *imgurl = urlAry[0];
                 if (imgurl.length > 0)
                 {
                     if (weakSelf.closeImgType == 0)
                     {
                         weakSelf.frontImgUrl = imgurl;

                     }
                     else
                     {
                         weakSelf.reveImgUrl = imgurl;
                     }
                 }
                 
             }
         }
         
     } failure:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:weakSelf.view animated:YES];
         
     } progress:^(CGFloat progress) {
         
     }];
    
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {
        return 400*displaywidth;
    }
    return 50*displaywidth;
}

- (void)submitAction
{
    if (!isSelect) {
        [LTools showMBProgressWithText:@"请先勾选协议,才可认证" addToView:self.view];
        return;
    }
    [self.view endEditing:YES];
    if ([_nameStr isEqualToString:@""])
    {
        [LTools showMBProgressWithText:@"请输入真实姓名" addToView:self.view];
        return;
    }
    if ([_carNumStr isEqualToString:@""])
    {
        [LTools showMBProgressWithText:@"请输入身份证号" addToView:self.view];
        return;
    }
    if ([_frontImgUrl isEqualToString:@""])
    {
        [LTools showMBProgressWithText:@"上传身份证正面照片" addToView:self.view];
        return;
    }
    if ([_reveImgUrl isEqualToString:@""])
    {
        [LTools showMBProgressWithText:@"上传身份证反面照片" addToView:self.view];
        return;
    }
    NSDictionary *dic = @{@"realName":_nameStr,
                          @"idCardNum":_carNumStr,
                          @"idCardFrontImg":_frontImgUrl,
                          @"idCardBackImg":_reveImgUrl
                          };
    [self requestIdentity:dic];
}

- (void)requestIdentity:(NSDictionary *)dic
{
    WEAKSELF;
    [HYBaseHandler requestIdentityParmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             NSString *orderCode = obj[@"data"][@"order"][@"code"];
             NSString *price = obj[@"data"][@"order"][@"price"];
             SecurityDepositViewController *vc = [[SecurityDepositViewController alloc] init];
             vc.priceStr = price;
             vc.orderNo = orderCode;
             [weakSelf.navigationController pushViewController:vc animated:YES];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];

         }
     } failed:^(NSError *error) {
         
     }];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.tag == 100)
    {
        _nameStr = textField.text;

    }
    else if (textField.tag == 101)
    {
        _carNumStr = textField.text;
    }
    
    
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
}


- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.view endEditing:YES];
    return indexPath;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
